#import "OmUserPageVCPhotoButton.h"
@interface OmUserPageVCPhotoButton ()
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) NSMutableArray<UIImageView *> *photos;
@end
@implementation OmUserPageVCPhotoButton
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self configSelf];
        [self allocateComponents];
        [self layoutComponents];
    }
    return self;
}
- (void)configSelf {
    self.backgroundColor = [UIColor whiteColor];
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(WINDOW_WIDTH));
        make.height.equalTo(@(RPX(80)));
    }];
}
- (void)allocateComponents {
    self.title = [[UILabel alloc] init].fp_text(ASLocalizedString(@"个人相册")).fp_font(RPXFont(14));
    [self addSubview:self.title];
}
- (void)layoutComponents {
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(RPX(15));
    }];
}
- (void)setModels:(NSArray<OmPictureModel *> *)models {
    _models = models;
    [self refreshPhotos:models];
}
- (void)refreshPhotos:(NSArray<OmPictureModel *> * _Nonnull)models {
    for (UIImageView *photo in self.photos) {
        [photo removeFromSuperview];
    }
    self.photos = [NSMutableArray array];
    for (int i=0; i<models.count; i++) {
        UIImageView *photo = [[UIImageView alloc] init];
        [self addSubview:photo];
        [self.photos addObject:photo];
        [photo sd_setImageWithURL:[NSURL URLWithString:models[i].img]];
        if (i == 2) break;
    }
    for (int i=0; i<self.photos.count; i++) {
        UIImageView *currentPhoto = self.photos[i];
        UIImageView *previousPhoto = self.photos[i-1];
        [currentPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.width.height.equalTo(@(RPX(60)));
            if (i == 0) {
                make.left.equalTo(self).offset(RPX(94));
            } else {
                make.left.equalTo(previousPhoto.mas_right).offset(RPX(13));
            }
        }];
    }
}
@end
